package com.wuyou.designPatterns.iterator;

/**
 * @Description 实际迭代器
 * @Author yh.zhang
 * @Date 2024/1/10 16:42
 */
public class BookShelfListIterator<T> implements Iterator{

    private final Aggregate<T> aggregate;

    private int index;

    public BookShelfListIterator(Aggregate<T> aggregate) {
        this.aggregate = aggregate;
        this.index = 0;
    }

    @Override
    public T next() {
        return aggregate.getBookAt(this.index++);
    }

    @Override
    public boolean hasNext() {
        if (index < aggregate.getLength()) {
            return true;
        }
        return false;
    }
}
